#include "GLcontext.h"



GLcontext::GLcontext(void) :key(0) {

	fprintf(stdout, "constructor\n");
}

GLcontext::~GLcontext(void) {
}


void GLcontext::SetupScene(void)
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Set the clear color based on Microsofts CornflowerBlue (default in XNA)  
	shader.LoadFromFile("Shader/vertex_shader.txt", Dengine::type::VERTEX_SHADER);
	shader.LoadFromFile("Shader/fragment_shader.txt", Dengine::type::FRAGMENT_SHADER);
	program = shader.ReturnProgram();

	font.CreateFontFT("Font/DeathNoteMain.ttf", program, 32, 96);

	glEnable(GL_BLEND);
	glDisable(GL_CULL_FACE);
	glDisable(GL_DEPTH_TEST);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

void GLcontext::ReshapeWindow(GLsizei w, GLsizei h) {
	windowWidth = w; // Set the window width  
	windowHeight = h; // Set the window height  
	font.GiveScreenSize(w, h);
}

void GLcontext::RenderScene(void) {
	glViewport(0, 0, windowWidth, windowHeight); // Set the viewport size to fill the window  
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Clear required buffers  
	glUseProgram(program);
	float sx = 2.0 / windowWidth;
	float sy = 2.0 / windowHeight;
	
	//font.DrawTextFT("DEATH NOTE", { -1 + 8 * sx, 1 - 50 * sy }, { sx, sy }, freetype::type::ALIGN_CENTER);
	//font.DrawTextFT("DEATH NOTE", { -1 + 8 * sx, 50 * sy }, { sx, sy }, freetype::type::ALIGN_CENTER);
	switch (key)
	{
	case 1:
		pointer = &firstscene;
		((Scene*)pointer)->RenderScene(); //Compiler do not know what type it is, so we need to say to what type it points to.
		break;
	case 2:
		pointer = &secondscene;
		((Scene_2*)pointer)->RenderScene(); //Compiler do not know what type it is, so we need to say to what type it points to.
		break;
	}
}